package com.yidu.BusinessParameters.service.impl;

import com.yidu.BusinessParameters.entity.CashAccruedEntity;
import com.yidu.BusinessParameters.mapper.CashAccruedMapper;
import com.yidu.BusinessParameters.service.CashAccruedEntityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CashAccruedEntityServiceImpl implements CashAccruedEntityService {

    @Autowired
    private CashAccruedMapper cashInventoryMapper;
    @Override
    public List<CashAccruedEntity> cashInventorySelect() {
        return cashInventoryMapper.cashInventorySelect();
    }

    /**
     * 查询
     * @param page
     * @param limit
     * @param cashInventoryEntity
     * @return
     */
    @Override
    public List<CashAccruedEntity> cashInventorySelects(int page, int limit, CashAccruedEntity cashInventoryEntity) {
        Map map = new HashMap<>();
        map.put("page",(page-1)*limit);
        map.put("limit",limit);
        map.put("moneyAllocate",strWriter(cashInventoryEntity));
        List<CashAccruedEntity> cashAccruedEntities = cashInventoryMapper.cashInventorySelects(map);
        return cashAccruedEntities;

    }

    /**
     * 增加
     * @param cashInventoryEntity
     * @return
     */
    @Override
    public int cashInventoryinsert(CashAccruedEntity cashInventoryEntity) {
         return cashInventoryMapper.cashInventoryinsert(cashInventoryEntity);
    }

    /**
     * 删除
     * @param cashAccruedId
     * @return
     */
    @Override
    public int cashInventorydelete(String cashAccruedId) {
         return cashInventoryMapper.cashInventorydelete(cashAccruedId);
    }

    /**
     * 修改
     * @param cashInventoryEntity
     * @return
     */
    @Override
    public int cashInventoryupdate(CashAccruedEntity cashInventoryEntity) {
        return cashInventoryMapper.cashInventoryupdate(cashInventoryEntity);
    }

    @Override
    public int cashDeleteNew(CashAccruedEntity cashAccruedEntity) {
        return cashInventoryMapper.cashDeleteNew(cashAccruedEntity);
    }

    @Override
    public int two() {
        return cashInventoryMapper.two();
    }

    //判断类型，时间
    public String strWriter(CashAccruedEntity cashAccruedEntity){
        StringBuffer buffer = new StringBuffer("");
        if (cashAccruedEntity.getBusinessType()!=0){
            buffer.append("and businessType = '"+cashAccruedEntity.getBusinessType()+"'");
        } if (cashAccruedEntity.getCashDate() != null && !cashAccruedEntity.getCashDate().equals("")){
            buffer.append("and cashDate = '"+cashAccruedEntity.getCashDate()+" '");
        }
        System.out.println("进入strWriter"+buffer.toString());
        return buffer.toString();
    }
}
